const BASE_URL = "https://admin.lykangshu.top"
// https://admin.lykangshu.top
// 封装请求方法
const token = uni.getStorageSync('token');

function request(url, method, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: method || 'POST',
			data: data,
			header: {
				'Content-Type': 'application/json', // 设置请求头
				"token": token || "",
				// "token": "0a58a6ad-d84e-40e8-939e-872307471886",
			},
			success: (res) => {
				if (res.data.code == 1) {
					resolve(res);
				} else if (res.data.code == 401) {
					uni.$u.toast("没登陆")
					uni.reLaunch({
						url: '/pages/login/login'
					})
				} else {
					uni.$u.toast(res.data.msg)
				}
			},
			fail: (err) => {
				reject(err);
			},
		});
	});
}
export default request;